<?php
class GuestbookController extends AppController {

    public $layout = 'main';

    function beforeFilter() {
        parent::beforeFilter(); 
    }

    function index(){
	    $this->loadModel('News');
	    $news=$this->News->find("all",array()); 
	    $this->set("news",$news); 
    }
    function guestbook(){
    	$params = $this->request->data;
    	$this->loadModel('Guestbook');  
    	if($this->request->is('post')){
    		if(empty($params['name'])){
                $this->ajaxReturn(4001, '请填写留言人');      //判断数据是否输入    
            }
            $databe =[];
            $databe['Guestbook']['name'] = $params['name'];
            $databe['Guestbook']['phone'] = $params['phone'];//写入数值
            $databe['Guestbook']['read'] = '2';
            $databe['Guestbook']['display'] = '2';
            $databe['Guestbook']['create_time'] = time();
            if(!$this->Guestbook->save($databe)){                        //存储数据，如果失败则报错
                $this->ajaxReturn(4004, '操作失败，请稍后再试'); 
            }else{
                $this->ajaxReturn(200, '操作成功！','','/guestbook/index');
            }
    	}    
    }

}